package cn.shop.transcation.frontUserModule;

import cn.hutool.core.lang.RegexPool;
import cn.shop.base.BaseEntity;
import cn.shop.utils.constant.Regular;
import cn.shop.validation.Save;
import cn.shop.validation.Update;
import com.baomidou.mybatisplus.annotation.SqlCondition;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.Version;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonProperty.Access;
import lombok.*;
import org.hibernate.validator.constraints.Length;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Pattern;
import java.math.BigDecimal;
import java.time.LocalDateTime;

/**
 * 购物平台用户表(FrontUser)表实体类
 *
 * @author jzw
 * @since 2022-01-07 15:45:20
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
@ToString
@EqualsAndHashCode(callSuper = true)
public class FrontUser extends BaseEntity {

	private static final long serialVersionUID = -8318328188811701896L;

	/**
	 * 账户
	 */
	@NotBlank(message = "账户不能为空", groups = Save.class)
	@Pattern(regexp = Regular.ACCOUNT, message = Regular.ACCOUNT_MASSAGE, groups = Save.class)
	private String account;

	/**
	 * 密码
	 */
	@JsonProperty(access = Access.WRITE_ONLY)
	@NotBlank(message = "密码不能为空", groups = Save.class)
	@Pattern(regexp = Regular.PASSWORD, message = Regular.PASSWORD_MASSAGE, groups = {Save.class, Update.class})
	private String password;

	/**
	 * 交易密码
	 */
	@JsonProperty(access = Access.WRITE_ONLY)
	private String transactionPassword;

	/**
	 * 姓名
	 */
	@TableField(condition = SqlCondition.LIKE)
	@Length(max = 10, groups = {Save.class, Update.class}, message = "姓名过长")
	@Pattern(regexp = Regular.NAME, message = Regular.NAME_MASSAGE, groups = {Save.class, Update.class})
	private String name;

	/**
	 * 性别 0 :男 1: 女
	 */
	@JsonFormat(shape = JsonFormat.Shape.NUMBER)
	private Boolean gender;

	/**
	 * 头像
	 */
	private String avatar;

	/**
	 * 充值后余额
	 */
	// @JsonProperty(access = Access.READ_ONLY)
	private BigDecimal balance;

	/**
	 * 提现冻结金额
	 */
	@JsonProperty(access = Access.WRITE_ONLY)
	private BigDecimal frozenAmount;

	/**
	 * 电话
	 */
	@Pattern(regexp = RegexPool.MOBILE, message = "请输入正确手机格式", groups = {Save.class, Update.class})
	private String phone;

	/**
	 * 是否实名认证
	 */
	@JsonProperty(access = Access.WRITE_ONLY)
	private Boolean certification;

	/**
	 * 身份证号
	 */
	private String identityCard;

	/**
	 * 账号是否有风险
	 */
	private Boolean risk;

	/**
	 * 是否为高级玩家 , 高级玩家才能充值
	 */
	private Boolean advanced;

	/**
	 * 是否自动提现
	 */
	private Boolean autoWithdraw;

	/**
	 * 是否可以改名
	 */
	private Boolean canRename;

	@JsonProperty(access = Access.WRITE_ONLY)
	private String openId;

	@JsonProperty(access = Access.WRITE_ONLY)
	private String unionId;

	@Version
	private Integer version;

	@TableField(exist = false)
	private String code;

	@TableField(exist = false)
	private boolean isWxBind;
	/**
	 * 最后登录时间
	 */
	private LocalDateTime lastLoginTime;
}

